
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/build/bin")
set(LIBRARY_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/build/lib")

set(GROUP_BY_DIR OFF)

#条件编译
if(CMAKE_HOST_UNIX)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -g -fpic -fPIC")
    set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -D_DEBUG -O0 -ggdb")
    set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2")

elseif (CMAKE_HOST_WIN32)
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    set(CMAKE_CXX_EXTENSIONS OFF)

    
    add_compile_definitions(_CRT_SECURE_NO_WARNINGS) # 禁止 strcat 等函数报 strcat_s 警告



    # 检测当前使用的编译器
    if(CMAKE_CXX_COMPILER_ID STREQUAL "MinGW")
        message(STATUS "Using MinGW compiler")
        link_libraries(ws2_32 mswsock advapi32 user32)
        set(Qt_PATH "C:/Qt/Qt5.14.2/5.14.2/mingw73_64")
        set(Qt5_DIR ${Qt_PATH}/lib/cmake/Qt5)
        
    elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
        message(STATUS "Using MSVC compiler")
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /source-charset:utf-8 /execution-charset:utf-8") # 设置编译选项，使 UTF8 格式的源文件

        add_definitions(-D_CRT_SECURE_NO_WARNINGS)
        add_compile_options(/wd4251)
        add_definitions(-D_WIN32_WINNT=0x0A00)
        
        set(Qt_PATH "C:/Qt/Qt5.14.2/5.14.2/msvc2017")
        set(Qt5_DIR ${Qt_PATH}/lib/cmake/Qt5)
    
    elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
        message(STATUS "Using Clang compiler")
        set(Qt_PATH "C:/Qt/Qt5.14.2/5.14.2/msvc2017_64")
        set(Qt5_DIR ${Qt_PATH}/lib/cmake/Qt5)

    else()
        message("Unknown compiler or generator:" ${CMAKE_CXX_COMPILER_ID})
        
    endif()
endif()
